package com.zyw.auth.shiro.service.impl;

import com.zyw.auth.common.IConstants;
import com.zyw.auth.dao.AdministratorDao;
import com.zyw.auth.dao.RightsDao;
import com.zyw.auth.domain.Administrator;
import com.zyw.auth.domain.Rights;
import com.zyw.auth.shiro.service.AdministratorRealmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>注意：此业务类，会在系统启动时，被shiro的reaml加载，不会被事务拦截器处理</p>
 * <p>故此类的方法都不支持事务</p>
 */
@Service("administratorRealmService")
public class AdministratorRealmServiceImpl implements AdministratorRealmService {
    @Autowired
    private AdministratorDao adminDao;
    @Autowired
    private RightsDao rightsDao;
    
    /**
     * 根据登录名查找后台管理员
     * @param userName 登录名
     */
    @Override
    public Administrator findByUserName(String userName) {
        return adminDao.findByUserName(userName, IConstants.C_PROPERTY_VALID);
    }

    /**
     * 根据管理员ID查询权限列表
     * @param adminId 管理员ID
     */
    @Override
    public List<Rights> queryRights(Long adminId) {
        return rightsDao.queryByAdminId(adminId, IConstants.C_PROPERTY_VALID);
    }

}
